<?php

class Application_Model_ActivityModel extends Zend_Db_Table_Abstract {

    protected $_name = "activities";
    protected $_primary = "idactivities";

    protected $_dependentTables = array("Application_Model_TaskModel");
    
    protected $_referenceMap    = array(
            'Actividades' => array(
                'columns'           => 'user_id',
                'refTableClass'     => 'Application_Model_UserModel',
                'refColumns'        => 'idusers'
            )
        );

    public function getActivities($page = "1", $elementsPerPage = "10", $where = NULL) {

        $select = $this->select("activities")->limitPage($page, $elementsPerPage);
        if ($where) {
            $select->where($where);
        }
        return $this->fetchAll($select);
    }

    public function getActivitiesByNow(){
         $auth = Zend_Auth::getInstance();
                $user = $auth->getIdentity();
        $select = $this->select()
                        ->from($this->name)
                        ->where("start_date <= now()")
                        ->where("user_id = ".$user->idusers);
        return $this->fetchAll($select);
    }

    

    public function countActivities() {
        $select = $this->select();
        $select->from($this->_name, 'COUNT(*) AS num');
        return $this->fetchRow($select)->num;
    }

}